Tell me about Action Method in Asp.Net MVC with a suitable example as well as a suitable image.
Explain Action Method parameter?
46730-Jan-2020
Updated on 30-Jan-2020
Home / DeveloperSection / Forums / Explain Action Method parameter?
Tell me about Action Method in Asp.Net MVC with a suitable example as well as a suitable image.
Nishi Tiwari
30-Jan-2020Action parameters are defined as the variables which are used to retrieve user-requested values from the URL.
The parameters are easily retrieved from the request's data collection. Parameters may include name or value pairs for data, query string value, etc. the controller class will locate for the values of the parameters based on the RouteData instance. If the value will present, it will be passed to the parameter else exception will be thrown.
The Controller class gives two properties Request and Response which can be used to get handle user requests and responses.
Example
Here, we are going to create an action method in the controller. This action method will have a parameter. The controller code may look like this:
// MusicStoreController.cs
Output:
In URL, we must have to pass the parameter value and we will do it by this URL localhost:port-no/MusicStore/ShowMusic?MusicTitle=Classic.
It will give the following output:-